package com.vpen.blog.consumer;
import com.vpen.blog.config.RabbitMQConfig;
import com.vpen.blog.service.BlogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.Map;

/**
 * -@Version 1.0
 * -@Author:Vpen
 * -@Date:2021/7/11 17:16
 * -@Content:消费着监听队列
 */
@Slf4j
@Component
public class DelayMessageConsumer {
    @Autowired
    BlogService blogService;
//    @RabbitListener(queues = RabbitMQConfig.Delay_Queue_Name)
//    public void receiveMessage(Message message){
//        String msg = new String(message.getBody());
//        log.info("当前时间：{},延迟队列收到消息{}", LocalDateTime.now(),msg);
//    }
    /**
     * 作者:Vpen
     * 描述:投递的消息需要序列化。。。。。。。request没有序列化
     * */
    @RabbitListener(queues = RabbitMQConfig.Delay_Queue_Name)
    public void receiveMessage(Map<String,Object> article){
        // 需要在这里进行调用添加文章，即可达到延迟的效果
        System.out.println(article);
        blogService.addArticle(article);
        log.info("当前时间：{},延迟队列收到消息{}", LocalDateTime.now(),article);
    }

}
